package com.acmen.easyapi.web;


import com.acmen.easyapi.dto.TestDataQry;
import com.acmen.easyapi.dto.UnitTestCmd;
import com.acmen.easyapi.model.Response;
import com.acmen.easyapi.dto.UnitTestAdd;
import com.acmen.easyapi.service.UnitTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author acmen
 * 单元测试服务
 * @date 2022-03-16
 */
@RestController
public class UnitTestController {
    @Autowired
    private UnitTestService unitTestService;

    @SuppressWarnings("unused")
    @PostMapping(value = "/api/test")
    public Response test(@RequestBody UnitTestCmd unitTestCmd, HttpServletResponse response) {
        return unitTestService.test(unitTestCmd,response);
    }

    @PostMapping(value = "/api/test-data")
    public Response getTestData(@RequestBody TestDataQry testDataQry) {
       return unitTestService.getTestData(testDataQry);
    }

    @PostMapping(value = "/test/unit-test")
    public Response saveUnitTest(@RequestBody UnitTestAdd unitTest) {
        return unitTestService.save(unitTest);
    }

    @GetMapping(value = "/test/unit-tests/{apiId}")
    public Response getUnitTests(@PathVariable String apiId) {
        return unitTestService.selectList(apiId);
    }

    @DeleteMapping(value = "/test/unit-test/{id}")
    public Response deleteUnitTest(@PathVariable String id) {
        return unitTestService.delete(id);
    }

    @PutMapping(value = "/test/unit-test/{id}/{join}")
    public Response joinPressureTest(@PathVariable("id") String id,@PathVariable("join") boolean join) {
        return unitTestService.joinPressureTest(id,join);
    }

    @GetMapping(value = "/test/log/{traceId}")
    public Response getTestLog(@PathVariable("traceId") String traceId,@RequestHeader("jwt") String jwt) {
        return unitTestService.getTestLog(traceId,jwt);
    }

}
